<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const input = [
            {
                username: 'zhangsan',
                starCount: 10,
                content: '嘻嘻嘻',
            },
            {
                username: 'lisi',
                starCount: 122,
                content: '嘿嘿',
            },
            {
                username: 'lisi',
                starCount: 99,
                content: '呵呵',
            },
            {
                username: 'zhangsan',
                starCount: 12,
                content: '哈哈哈',
            },
            {
                username: 'wangwu',
                starCount: 6,
                content: '嗯嗯',
            },
        ];
        const output = {
            starCount: {
                zhangsan: 22,
                lisi: 221,
                wangwu: 6,
            },
            commentCount: {
                zhangsan: 2,
                lisi: 2,
                wangwu: 1,
            },
        };
        function getTotal(input) {
            const starCount = {};
            const commentCount = {};
            for (const item of input) {
                const {
                    username,
                    // 把starCount重新声明为s
                    starCount:s,
                } = item;
                if (!commentCount[username]) {
                    commentCount[username] = input.filter(cmt => cmt.username === username).length;
                    starCount[username] = s;
                } else {
                    starCount[username] += s;
                }
            }
            return {
                starCount,
                commentCount,
            };
        }
        console.log(getTotal(input));
     </script>
</body>
</html>